package com.wewins.fota.sys;

import com.wewins.fota.sys.service.FotaCacheManager;
import com.wewins.fota.sys.service.LogInitService;
import com.wewins.fota.sys.service.RedisFotaLogService;
import com.wewins.fota.sys.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 应用初始化动作
 */

@Component
@Order(1)
public class StartRunner implements CommandLineRunner {
    private final FotaCacheManager fotaCacheManager;
    private final RedisFotaLogService redisFotaLogService;
    private final StatisticService frequencyService;
    private final LogInitService logInitService;

    @Autowired
    public StartRunner(
            FotaCacheManager fotaCacheManager,
            RedisFotaLogService redisFotaLogService,
            StatisticService frequencyService,
            LogInitService logInitService
    ) {
        this.fotaCacheManager = fotaCacheManager;
        this.redisFotaLogService = redisFotaLogService;
        this.frequencyService = frequencyService;
        this.logInitService = logInitService;
    }

    @Override
    public void run(String... args) throws Exception {
        fotaCacheManager.rebuildCache();
        redisFotaLogService.initService();
        frequencyService.initService();
        logInitService.initLog();
    }

}
